<html>
<head><meta charset="utf-8"><title>What were the interning gains in bootstrap? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html">What were the interning gains in bootstrap?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203655823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203655823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203655823">(Jul 12 2020 at 18:51)</a>:</h4>
<p>The bootstrap tool makes heavy use of string interning and has a global string pool. What kinds of benefits did we get from going from non-interning to interning for this specific tool?</p>
<p>/cc <span class="user-mention" data-user-id="116122">@simulacrum</span></p>



<a name="203656209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203656209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203656209">(Jul 12 2020 at 19:01)</a>:</h4>
<p>Another way to put that question would be: Does the bootstrap tool do enough work that optimizations are worth it?</p>



<a name="203656429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203656429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203656429">(Jul 12 2020 at 19:06)</a>:</h4>
<p>It's not about optimization, just ease of use of Copy vs cloning things. But I would hope that there's more details in the commit introducing it - I forget if I wrote that up.</p>



<a name="203656434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203656434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203656434">(Jul 12 2020 at 19:06)</a>:</h4>
<p>We don't even compile bootstrap with optimizations enabled IIRC</p>



<a name="203660537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203660537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203660537">(Jul 12 2020 at 20:53)</a>:</h4>
<p>heh I've done similar things, although not globally (always with contexts)</p>



<a name="203660598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203660598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203660598">(Jul 12 2020 at 20:54)</a>:</h4>
<p>kind of wish interning arbitrary data was easier, it's <em>so</em> useful, and IMO higher-level languages should do it by default (possibly in a way in which they can do GC? so like a <code>WeakMap</code> of sorts?)</p>



<a name="203660615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203660615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203660615">(Jul 12 2020 at 20:55)</a>:</h4>
<p>(really getting off-topic here, but has anyone heard of any language, even a toy one, that interns everything?)</p>



<a name="203660626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203660626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203660626">(Jul 12 2020 at 20:55)</a>:</h4>
<p>/me has had ideas around those lines for very domain-specific designs but hasn't had the time to implement any</p>



<a name="203661099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661099">(Jul 12 2020 at 21:07)</a>:</h4>
<p>Yeah I think contexts make sense for anything that has a possiblity of caring about memory usage - bootstrap interns usually like 10 things per run I suspect so really not worth the hassle of pulling a context around (mostly into e.g. serde deserialization)</p>



<a name="203661111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661111">(Jul 12 2020 at 21:07)</a>:</h4>
<blockquote>
<p>It's not about optimization, just ease of use of Copy </p>
</blockquote>
<p>I had a feeling, which is why I used the broadly-applicable "gains" ;-)</p>



<a name="203661161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661161">(Jul 12 2020 at 21:08)</a>:</h4>
<p>Why not just <code>String::leak</code> everything?</p>



<a name="203661169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661169">(Jul 12 2020 at 21:08)</a>:</h4>
<p>And why doesn't <code>String::leak</code> actually exist.</p>



<a name="203661240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661240">(Jul 12 2020 at 21:10)</a>:</h4>
<p>We could, yeah, that'd be fine by me personally if someone wanted to post a PR doing so, though we'd still want to retain the HashMaps that track what we've already interned I suspect</p>



<a name="203661247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661247">(Jul 12 2020 at 21:10)</a>:</h4>
<p>(it's also somewhat true that &amp;'static str is a pain to write)</p>



<a name="203661257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661257">(Jul 12 2020 at 21:11)</a>:</h4>
<p>The current solution is of course not better in that respect</p>



<a name="203661319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661319">(Jul 12 2020 at 21:12)</a>:</h4>
<blockquote>
<p>track what we've already interned I suspect</p>
</blockquote>
<p>for bootstrap; why?</p>



<a name="203661385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661385">(Jul 12 2020 at 21:14)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> I'm not sure -- we'd have to look -- if we call the interner in too many places it could begin to start using more memory than I'm comfortable with</p>



<a name="203661388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661388">(Jul 12 2020 at 21:14)</a>:</h4>
<p><code>String::leak</code> goes through <code>Box</code>: <code>String -&gt; Box&lt;str&gt; -&gt; &amp;'static mut str</code></p>



<a name="203661389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661389">(Jul 12 2020 at 21:14)</a>:</h4>
<p>but realistically probably doesn't matter</p>



<a name="203661482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661482">(Jul 12 2020 at 21:16)</a>:</h4>
<p>we currently have an unstable <code>fn Vec::leak</code>, so it's probably just that noone cared enough to open a PR yet</p>



<a name="203661511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661511">(Jul 12 2020 at 21:17)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> I was just going by "bootstrap interns usually like 10 things per run" ;-)</p>



<a name="203661520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661520">(Jul 12 2020 at 21:18)</a>:</h4>
<p><span class="user-mention" data-user-id="229913">@HeroicKatora</span> too long wouldn't type</p>



<a name="203661770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661770">(Jul 12 2020 at 21:23)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> well 10 things but maybe 10,000 times, I don't know :)</p>



<a name="203661843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661843">(Jul 12 2020 at 21:25)</a>:</h4>
<p>I wonder how well e.g. the <code>string_cache</code> crate would work here (I don't actually know how each and all of the crates work etc.)</p>



<a name="203661911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203661911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203661911">(Jul 12 2020 at 21:26)</a>:</h4>
<p>That wasn't actually supposed to be against it, more an endorsement since it's already possible :)</p>



<a name="203662031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203662031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203662031">(Jul 12 2020 at 21:29)</a>:</h4>
<p>we probably don't want another dependency</p>



<a name="203662973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203662973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203662973">(Jul 12 2020 at 21:55)</a>:</h4>
<p>heh</p>



<a name="203663029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203663029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203663029">(Jul 12 2020 at 21:56)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> does <code>bootstrap</code> have threads? is the interner truly global, or just thread-local? and if it's not thread-local, have you tried it? I guess it can't change much heh</p>



<a name="203663042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203663042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203663042">(Jul 12 2020 at 21:56)</a>:</h4>
<p>global has the advantage that you can use <code>&amp;'static str</code> inside your interned string and deref to str</p>



<a name="203663043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203663043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203663043">(Jul 12 2020 at 21:56)</a>:</h4>
<p>no threads</p>



<a name="203663044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203663044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203663044">(Jul 12 2020 at 21:56)</a>:</h4>
<p>I think we do just deref to that</p>



<a name="203663046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203663046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203663046">(Jul 12 2020 at 21:56)</a>:</h4>
<p>fair</p>



<a name="203665973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203665973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203665973">(Jul 12 2020 at 23:21)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> does <code>bootstrap</code> need to compile without nightly features?</p>



<a name="203665976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203665976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203665976">(Jul 12 2020 at 23:21)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(drain_filter)]</span><span class="w"></span>
</code></pre></div>


<p>I guess not</p>



<a name="203666038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203666038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203666038">(Jul 12 2020 at 23:22)</a>:</h4>
<p>I would like it to, generally speaking</p>



<a name="203666187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203666187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203666187">(Jul 12 2020 at 23:27)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(hash_raw_entry)]</span><span class="w"></span>

<span class="k">use</span><span class="w"> </span><span class="n">once_cell</span>::<span class="n">sync</span>::<span class="n">Lazy</span><span class="p">;</span><span class="w"> </span><span class="c1">// 1.4.0</span>
<span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="p">{</span><span class="n">collections</span>::<span class="n">HashMap</span><span class="p">,</span><span class="w"> </span><span class="n">sync</span>::<span class="n">Mutex</span><span class="p">};</span><span class="w"></span>

<span class="k">static</span><span class="w"> </span><span class="n">STRINGS</span>: <span class="nc">Lazy</span><span class="o">&lt;</span><span class="n">Mutex</span><span class="o">&lt;</span><span class="n">HashMap</span><span class="o">&lt;&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="p">()</span><span class="o">&gt;&gt;&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Lazy</span>::<span class="n">new</span><span class="p">(</span><span class="nb">Default</span>::<span class="n">default</span><span class="p">);</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">intern</span><span class="o">&lt;</span><span class="n">S</span><span class="o">&gt;</span><span class="p">(</span><span class="n">s</span>: <span class="nc">S</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="kt">str</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="n">S</span>: <span class="nb">Into</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nb">AsRef</span><span class="o">&lt;</span><span class="kt">str</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">pool</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">STRINGS</span><span class="p">.</span><span class="n">lock</span><span class="p">().</span><span class="n">expect</span><span class="p">(</span><span class="s">&quot;Pool poisoned&quot;</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="p">(</span><span class="n">k</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">pool</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">raw_entry_mut</span><span class="p">()</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">from_key</span><span class="p">(</span><span class="n">s</span><span class="p">.</span><span class="n">as_ref</span><span class="p">())</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">or_insert_with</span><span class="p">(</span><span class="o">||</span><span class="w"> </span><span class="p">(</span><span class="nb">Box</span>::<span class="n">leak</span><span class="p">(</span><span class="n">s</span><span class="p">.</span><span class="n">into</span><span class="p">().</span><span class="n">into_boxed_str</span><span class="p">()),</span><span class="w"> </span><span class="p">()));</span><span class="w"></span>
<span class="w">    </span><span class="n">k</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="203666193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203666193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203666193">(Jul 12 2020 at 23:27)</a>:</h4>
<p>But it's so pretty</p>



<a name="203666201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203666201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203666201">(Jul 12 2020 at 23:27)</a>:</h4>
<p>But we always compile it with beta so it shouldn't be a problem in theory for it to be built with nightly features</p>



<a name="203667543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667543">(Jul 13 2020 at 00:07)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> sadly you lose O(1) comparison - but maybe that's not needed here</p>



<a name="203667594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667594">(Jul 13 2020 at 00:08)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> why is it lost? (<a href="https://play.integer32.com/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=7c6e8954128c003cd827adfc68379d9c">Playground if you want to demo something</a>)</p>



<a name="203667598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667598">(Jul 13 2020 at 00:08)</a>:</h4>
<p>because you're not wrapping it in a type that compares e.g. address instead of contents</p>



<a name="203667608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667608">(Jul 13 2020 at 00:09)</a>:</h4>
<p>Doesn't <code>PartialEq</code> for str / slice start with an address comparison?</p>



<a name="203667618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667618">(Jul 13 2020 at 00:09)</a>:</h4>
<p>even if it does, it can't assume that address != implies contents !=</p>



<a name="203667619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667619">(Jul 13 2020 at 00:09)</a>:</h4>
<p>which the main reason compilers use interning (for strings, anyway, other things have less useful implications from !=)</p>



<a name="203667666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667666">(Jul 13 2020 at 00:10)</a>:</h4>
<p>I'm pretty sure it starts with <code>if (my.len == other.len &amp;&amp; my.data == other.data)</code></p>



<a name="203667668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667668">(Jul 13 2020 at 00:10)</a>:</h4>
<p>that's == not !=</p>



<a name="203667670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667670">(Jul 13 2020 at 00:11)</a>:</h4>
<p>if the address differs, it has to look at the contents</p>



<a name="203667677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667677">(Jul 13 2020 at 00:11)</a>:</h4>
<p>if you used a wrapper, you need 0 data accesses to the contents</p>



<a name="203667678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667678">(Jul 13 2020 at 00:11)</a>:</h4>
<p>ever</p>



<a name="203667679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667679">(Jul 13 2020 at 00:11)</a>:</h4>
<p>it would <em>only</em> compare the address</p>



<a name="203667680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667680">(Jul 13 2020 at 00:11)</a>:</h4>
<p>Oh, you are saying losing O(1) when they aren't equal</p>



<a name="203667681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667681">(Jul 13 2020 at 00:11)</a>:</h4>
<p>(not even the length, really :P)</p>



<a name="203667684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667684">(Jul 13 2020 at 00:11)</a>:</h4>
<p>cause it's still O(1) when they are equal</p>



<a name="203667685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667685">(Jul 13 2020 at 00:11)</a>:</h4>
<p>well, yeah, sometimes you'll compare things which aren't equal :P</p>



<a name="203667718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667718">(Jul 13 2020 at 00:12)</a>:</h4>
<p>well, you just said "lose"</p>



<a name="203667727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667727">(Jul 13 2020 at 00:12)</a>:</h4>
<p>comparison is not O(1) unless it's <em>always</em> O(1)</p>



<a name="203667729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667729">(Jul 13 2020 at 00:12)</a>:</h4>
<p>having a fast path is not related to O(1) outside of amortization</p>



<a name="203667742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667742">(Jul 13 2020 at 00:13)</a>:</h4>
<p>similarly, empty strings are O(1) to compare, but that doesn't really say anything about comparing strings in general, it's just an edge case</p>



<a name="203667753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667753">(Jul 13 2020 at 00:13)</a>:</h4>
<p>yes yes</p>



<a name="203667792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667792">(Jul 13 2020 at 00:14)</a>:</h4>
<p>You are correct. I apologize.</p>



<a name="203667795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667795">(Jul 13 2020 at 00:14)</a>:</h4>
<p>I should apologize for the random pedantry :P</p>



<a name="203667800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667800">(Jul 13 2020 at 00:14)</a>:</h4>
<p>No, it's very important to be correct when discussing things.</p>



<a name="203667801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667801">(Jul 13 2020 at 00:14)</a>:</h4>
<p>anyway I wanted to say that it probably doesn't matter for bootstrap, and being able to combine string literals and interning matters more</p>



<a name="203667808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667808">(Jul 13 2020 at 00:15)</a>:</h4>
<p>concept: <code>iformat!(...)</code> that expands to <code>intern(format!(...))</code></p>



<a name="203667819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667819">(Jul 13 2020 at 00:15)</a>:</h4>
<p>or <code>intern!(...)</code></p>



<a name="203667888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667888">(Jul 13 2020 at 00:17)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> oh a neat trick for interning, which <span class="user-mention" data-user-id="116122">@simulacrum</span> I believe added to rustc a while back, is to use something like a "small vec" to collect an iterator into (or in this case, a "small str" to format into), avoiding needing to do any heap allocations in the common case, before hitting the cache</p>



<a name="203667944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667944">(Jul 13 2020 at 00:18)</a>:</h4>
<p>if you get a cache miss, you then arena-allocate/leak the contents whichever way you prefer, but for cache hits, it's kind of "free"</p>



<a name="203667950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203667950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203667950">(Jul 13 2020 at 00:18)</a>:</h4>
<p>(not really because of various overheads, but it tends to be cheaper than having to allocate)</p>



<a name="203668019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203668019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203668019">(Jul 13 2020 at 00:20)</a>:</h4>
<p>I'm not following where the iterator is coming from; is this specifically in relation to the combined interning / formatting?</p>



<a name="203668029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203668029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203668029">(Jul 13 2020 at 00:20)</a>:</h4>
<p>yeah the iterator is specifically from the interned equivalent of a <code>Vec&lt;T&gt;</code></p>



<a name="203668031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203668031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203668031">(Jul 13 2020 at 00:20)</a>:</h4>
<p>whereas here you have a <code>String</code></p>



<a name="203668048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20were%20the%20interning%20gains%20in%20bootstrap%3F/near/203668048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20were.20the.20interning.20gains.20in.20bootstrap.3F.html#203668048">(Jul 13 2020 at 00:21)</a>:</h4>
<p>also applies if you have a constant (e.g. a string literal), but if you're not wrapping it, there's no reason to intern constants</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>